package com.latam.arq.example.web.listeners;

import javax.faces.context.ExternalContext;
import javax.faces.event.PhaseEvent;
import javax.faces.event.PhaseId;
import javax.faces.event.PhaseListener;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class AllPhaseListener implements PhaseListener{
	private static final Logger logger = LoggerFactory.getLogger(AllPhaseListener.class);
	
	private static final long serialVersionUID = -8800379624645640601L;

	@Override
	public void afterPhase(PhaseEvent pe) {		
		final ExternalContext ec = pe.getFacesContext().getExternalContext();
		if (logger.isInfoEnabled()){
			logger.info("(after " + pe.getPhaseId().toString() + ") " + ec.getRequestServletPath() );
		}
	}

	@Override
	public void beforePhase(PhaseEvent pe) {
		final ExternalContext ec = pe.getFacesContext().getExternalContext();
		if (logger.isInfoEnabled()){
			logger.info("(before " + pe.getPhaseId().toString() + ") " + ec.getRequestServletPath() );
		}
	}

	@Override
	public PhaseId getPhaseId() {
		return PhaseId.ANY_PHASE;
	}

}
